package com.woniuxy.Controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.RbacPerm;
import com.woniuxy.entity.RbacPermDto;
import com.woniuxy.service.RbacPermService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (RbacPerm)表控制层
 *
 * @author mayuhang
 * @since 2021-04-25 23:04:55
 */
@RestController
@RequestMapping("rbacPerm")
public class RbacPermController {
    /**
     * 服务对象
     */
    @Resource
    private RbacPermService rbacPermService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public RbacPerm selectOne(Integer id) {
        return this.rbacPermService.queryById(id);
    }
    /**
     * Description : TODO  <br/>
     * ChangeLog : 1. 创建 (2021/4/26 10:01 [mayuhang]);
     * @param startpage 开始查询的页数
     * @param pagesize  每页显示条数
     * @return com.woniuxy.entity.RbacPerm
     **/
    @GetMapping("selectAll")
    public PageInfo<RbacPerm> selectOne(int startpage,int pagesize) {
        PageHelper.startPage(startpage,pagesize);
        Page<RbacPerm> page = (Page<RbacPerm>) this.rbacPermService.queryAllByLimit();
        PageInfo<RbacPerm> pageInfo = new PageInfo<>(page);
        return pageInfo;
    }

    @RequestMapping("addPerm")
    public String addPerm(@RequestBody RbacPerm rbacPerm){
        this.rbacPermService.insert(rbacPerm);
        return "success";
    }

    @RequestMapping("deletePerm/{id}")
    public String deletePerm(@PathVariable("id") int id){
        this.rbacPermService.deleteById(id);
        return "success";
    }
    @RequestMapping("updatePerm")
    public String updatePerm(@RequestBody RbacPerm rbacPerm){
        this.rbacPermService.update(rbacPerm);
        return "success";
    }
    @RequestMapping("search")
    public PageInfo<RbacPerm> search(@RequestBody RbacPermDto rbacPermDto){
        System.out.println(rbacPermDto.toString());
        PageHelper.startPage(rbacPermDto.getPage(),rbacPermDto.getLimit());
        List<RbacPerm> search = this.rbacPermService.search(rbacPermDto.getRbacPerm());
        Page<RbacPerm> page = (Page) search;
        PageInfo<RbacPerm> pageInfo = new PageInfo<>(page);
        return pageInfo;
    }

}
